Skip to content

Clarify that static variables are not synonymous with global variables - #4825

Open
seven7763 wants to merge 1 commit into
rust-lang:mainfrom
seven7763:fix/ch20-01-static-vs-global
Open

Clarify that static variables are not synonymous with global variables#4825
seven7763 wants to merge 1 commit into
rust-lang:mainfrom
seven7763:fix/ch20-01-static-vs-global

Conversation

@seven7763

Copy link
Copy Markdown

Summary

Fixes #4819.

Section 20.1 said "In Rust, global variables are called static variables", which reads as global == static. A static item is defined by its 'static lifetime, not by its scope: per the Reference, static items may be declared at module scope or inside a function. This rewords the paragraph to make that distinction while keeping the section's flow into Listing 20-10.

Changes

  • src/ch20-01-unsafe-rust.md: reworded one paragraph (3 lines) in the "Accessing or Modifying a Mutable Static Variable" section.

Validation

  • Checked the wording against the Rust Reference on static items (statics have program lifetime and may appear in any scope)
  • dprint check src/ch20-01-unsafe-rust.md — the two reported regions (lines ~337-343, ~493+) also fail on unmodified main; they are pre-existing and outside this change's lines (~390-400).

Notes

Kept the change minimal — no restructuring of the section, just the incorrect equivalence.

"In Rust, global variables are called _static_ variables" implies
global == static, but a static item is about the 'static lifetime of the
binding, not its scope: static items may be declared at module scope or
inside a function.

Fixes rust-lang#4819
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading equivalence between global and static variables

1 participant